<%@page import="org.springframework.web.bind.annotation.RequestMethod"%>
<%@page import="cn.egame.interfaces.EnumType.GameTagType"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@page import="java.util.List"%>
<%@page import="cn.egame.common.model.*"%>
<%@page import="cn.egame.interfaces.gc.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script type="text/javascript">  
	function listTagsById(){
		var myform = document.getElementById("myform");
		myform.action = "<%=request.getContextPath() + "/tv/tag/list.do" %>";
		myform.submit();
	}
	function addTag(){
		var isSubmit = false;
		if(document.getElementById("tagName").value==""){
			alert("请填写关键字");
			return;
		}
		var i=0;
		var name = $("#tagName").val();
		$.ajax({		
			url : '<%=request.getContextPath() + "/tv/tag/search.do" %>',
			type : 'post',
			success : function(msg) {
				if(msg != null){
					$.each(msg,function(key,values){ 
						if(name==values){
							i++;
						}
					});  
				}
				
				if(i==0){
					isSubmit = true;
				}else{
					isSubmit = false;
					alert("此关键字已存在");
				}
				
				if(isSubmit){
					document.getElementById("addtag").submit();
				}else{
					return;
				}
			}
		});
	}
</script>
<script type="text/javascript" src="<%=request.getContextPath() %>/js/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="<%=request.getContextPath() %>/js/common.js"></script>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link type="text/css" rel="stylesheet" href="<%=request.getContextPath() %>/css/main.css"  />
<title>搜索关键字</title>
</head>
<body>
<form id="myform" name="myform" action="<%=request.getContextPath() + "/tv/tag.do" %>" method="post">
<div class="matter_box">
	<h3 class="nopoint"><strong>搜索关键字</strong></h3>
	<input type="hidden" id="tagType" name="tagType" value="<%=GameTagType.searchTag.value() %>">
	<%-- <select id="tagType" name="tagType" onchange="listTagsById()">
		<%
			GameTagType selectedType = GameTagType.none;
			if(request.getAttribute("tagType") != null){
				selectedType = GameTagType.lookup((Integer)request.getAttribute("tagType"));
			}
			for(GameTagType type:GameTagType.values()){
				%>
					<option
						value="<%=type.value() %>"
						<% if(type == selectedType){
							%>
						selected="selected"
							<%
						} %>
					>
						<%=type.name() %>
					</option>
				<%
			}
		%>
	</select> --%>
	<p class="tr"><a class="btn2" href="javascript:setDialog('addTag')">新增关键字</a></p>
	<div class="mt10 clearfix pt10">
		<table cellpadding="0" cellspacing="0" class="table2">
				<tr>
					<th>关键字编号</th>
					<th>关键字</th>
					<th>备注</th>
					<th>操作</th>
				</tr>
				<%
					if(request.getAttribute("pd")!=null){
						PageData pd = (PageData)request.getAttribute("pd");
						if(pd.getContent()!=null){
							List<GameTagInfo> list = (List<GameTagInfo>)pd.getContent();
							for(GameTagInfo bean:list){
								%>
									<tr class="keyTr">
										<td><%=bean.getTagId() %></td>
										<td class="keyTd"><%=bean.getTagName() %> </td>
										<td><%=bean.getRemark() %> </td>
										<td>
											<a href="<%=request.getContextPath() + "/tv/tag/delete.do?tagId=" + bean.getTagId() %>">删除</a>
										</td>
									</tr>
								<%
							}
						}
					}
				%>
			</table>
		<%@ include file="../page.in"  %> 
		</div>
</div>
</form>
<div class="dialog_table editor_group" id="addTag" style="width:400px">
	<h2 class="tc">新增关键字</h2>
	<form id="addtag" action="<%=request.getContextPath() + "/tv/tag/add.do"%>" method="post">
		<table>
			<tr>
				<td align="right">关键字:</td>
				<td class="pl25">
					<input type=text name=tagName id=tagName>
				</td>
			</tr>
			<tr style="display: none;">
				<td align="right">标签类型:</td>
				<td class="pl25">
					<%-- <%
						GameTagType type = GameTagType.none;
						if(request.getAttribute("tagType")!=null){
							type = GameTagType.lookup((Integer)request.getAttribute("tagType"));
						}
					%> --%>
					<%=GameTagType.searchTag %>
					<input type="hidden" name=tagTypeNum value=<%=GameTagType.searchTag.value() %>>
				</td>
			</tr>
			<tr>
				<td align="right">备注:</td>
				<td class="pl25">
					<input type=text name=remark>
				</td>
			</tr>
			
			<tr>
				<td colspan=2 align="center">
					<input type="button" class="btn3" value="提交" onclick="addTag()">
				</td>			
			</tr>
		</table>
	</form>
</div>
</body>
</html>